package l1j.server.server.model;

import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.server.model.Instance.L1PcInstance;

public class MpReductionByAwake extends TimerTask {
	private static Logger _log = Logger.getLogger(MpReductionByAwake.class.getName());

	private final L1PcInstance _pc;

	public MpReductionByAwake(final L1PcInstance pc) {
		this._pc = pc;
	}

	/**
	 * ・MP消費「4秒ごとに8」→「4秒ごとに6」に変更
	 */
	public void decreaseMp() {
		int newMp = this._pc.getCurrentMp() - 6;
		if (newMp < 0) {
			newMp = 0;
			L1Awake.stop(this._pc);
		}
		this._pc.setCurrentMp(newMp);
	}

	@Override
	public void run() {
		try {
			if (this._pc.isDead()) {
				return;
			}
			this.decreaseMp();
		} catch (final Throwable e) {
			_log.log(Level.WARNING, e.getLocalizedMessage(), e);
		}
	}

}
